// ////////////省份/////////////////////////
var provinceTpl = new Ext.XTemplate('</div><tpl for=".">'
		+ '	<div class="search-item">', '{text}', '	</div>' + '</tpl>');
var province_store = new Ext.data.Store({
	proxy : new Ext.data.HttpProxy({
		url : '/scmMng/proCity.do?method=getProvinces'
	}),
	reader : new Ext.data.JsonReader({
		totalProperty : 'result.totalCount',
		root : 'result.result'
	}, [{
		name : 'name'
	}, {
		name : 'text'
	}])
});



var province = new Ext.form.ComboBox({
	 readOnly : true,
	name:'province',
	fieldLabel : '省份',
	store : province_store,
	displayField : 'text',
	valueField : 'name',
	typeAhead : true,
	mode : 'remote',
	triggerAction : 'all',
	selectOnFocus : true,
	itemSelector : 'div.search-item',
	tpl :  provinceTpl,
	listWidth : 180,
//	emptyText : '请选择...',
	anchor : '95%',
	listWidth : 250,
	queryDelay : 0,
	//pageSize : 10,
	listeners : {
		'select' : function() {
			city_store.baseParams.province = province.getValue();
			city_store.reload();
			city.setValue("");
		}
	}
});

var newProvince  = function(){
	var province = new Ext.form.ComboBox({
		 readOnly : true,
	name:'province',
	fieldLabel : '省份',
	store : province_store,
	displayField : 'text',
	valueField : 'text',
	typeAhead : true,
	readOnly:true,
	mode : 'remote',
	triggerAction : 'all',
	selectOnFocus : true,
	itemSelector : 'div.search-item',
	tpl :  provinceTpl,
	listWidth : 180,
//	emptyText : '请选择...',
	anchor : '95%',
	listWidth : 250,
	queryDelay : 0,
	//pageSize : 10,
	listeners : {
		'select' : function() {
			city_store.baseParams.province = province.getValue();
			//alert(province.getValue());
			city_store.reload();
		}
	}
});
return province;
}
//////////////// END 省份//////////////////////////

/////////////////////// 城市//////////
var cityTpl = new Ext.XTemplate('</div><tpl for=".">'
		+ '	<div class="search-item">', '{text}', '	</div>' + '</tpl>');
var city_store = new Ext.data.Store({
	proxy : new Ext.data.HttpProxy({
		url : '/scmMng/proCity.do?method=getCities'
	}),
	reader : new Ext.data.JsonReader({
		totalProperty : 'result.totalCount',
		root : 'result.result'
	}, [{
		name : 'name'
	}, {
		name : 'text'
	}])
});

var city = new Ext.form.ComboBox({
	 readOnly : true,
	name:'city',
	fieldLabel : '城市',
	store : city_store,
	displayField : 'text',
	valueField : 'text',
	typeAhead : true,
	mode : 'remote',
	triggerAction : 'all',
	selectOnFocus : true,
	itemSelector : 'div.search-item',
	tpl :  cityTpl,
	listWidth : 180,
//	emptyText : '请选择...',
	anchor : '95%',
	listWidth : 250,
	queryDelay : 0,
	//pageSize : 10,
	listeners : {
		'select' : function() {
		//	ds1.baseParams.itemId = item.getValue();
			//ds1.reload();
		}
	}
});
var newCity = function(){
	var city = new Ext.form.ComboBox({
		 readOnly : true,
	name:'city',
	fieldLabel : '城市',
	store : city_store,
	displayField : 'text',
	valueField : 'text',
	typeAhead : true,
	mode : 'remote',
	readOnly:true,
	triggerAction : 'all',
	selectOnFocus : true,
	itemSelector : 'div.search-item',
	tpl :  cityTpl,
	listWidth : 180,
//	emptyText : '请选择...',
	anchor : '95%',
	listWidth : 250,
	queryDelay : 0,
	//pageSize : 10,
	listeners : {
		'select' : function() {
		//	ds1.baseParams.itemId = item.getValue();
			//ds1.reload();
		}
	}
});
return city;
}
//////////////end 城市///////////////////////////

///////////行业组件下拉列表框///////////////////////////////
var industryTpl = new Ext.XTemplate('</div><tpl for=".">'
		+ '	<div class="search-item">', '{text}', '	</div>' + '</tpl>');
var industry_store = new Ext.data.Store({
	proxy : new Ext.data.HttpProxy({
		url : '/scmMng/proCity.do?method=getIndustry'
	}),
	reader : new Ext.data.JsonReader({
		totalProperty : 'result.totalCount',
		root : 'result.result'
	}, [{
		name : 'name'
	}, {
		name : 'text'
	}])
});



var industry = new Ext.form.ComboBox({
	 readOnly : true,
	name:'industry',
	fieldLabel : '行业',
	store : industry_store,
	displayField : 'text',
	valueField : 'name',
	typeAhead : true,
	mode : 'remote',
	triggerAction : 'all',
	selectOnFocus : true,
	itemSelector : 'div.search-item',
	tpl :  industryTpl,
	listWidth : 180,
//	emptyText : '请选择...',
	anchor : '95%',
	listWidth : 250,
	queryDelay : 0
});

var newIndustry = function(conf){
	if(!conf)
		conf={};
	if(!conf.listWidth) 
       conf.listWidth= 180;
	var industry = new Ext.form.ComboBox({
    readOnly : true,
	name:'industry',
	fieldLabel : '行业',
	store : industry_store,
	displayField : 'text',
	valueField : 'name',
	typeAhead : true,
	mode : 'remote',
	triggerAction : 'all',
	selectOnFocus : true,
	itemSelector : 'div.search-item',
	tpl :  industryTpl,
	listWidth : conf.listWidth ,
	anchor : conf.anchor, 
	queryDelay : 0
});
return industry;
}
///////////行业组件下拉列表框  END ///////////////////////////////

//////////////////////银行类别//////////////////////////////////////
var bankTpl = new Ext.XTemplate('</div><tpl for=".">'
		+ '	<div class="search-item">', '{text}', '	</div>' + '</tpl>');
var bank_store = new Ext.data.Store({
	proxy : new Ext.data.HttpProxy({
		url : '/scmMng/proCity.do?method=getBank'
	}),
	reader : new Ext.data.JsonReader({
		totalProperty : 'result.totalCount',
		root : 'result.result'
	}, [{
		name : 'name'
	}, {
		name : 'text'
	}]),
	listeners : {
		load :function(store){// filter		
				store.filterBy( function(rec , id){
					var text = rec.get( "text" );
					if( text == '中国人民银行' ){
						return false;
					}else{
						return true
					}
				} );
		}
	}
});

var bankType = new Ext.form.ComboBox({
	 readOnly : true,
	name:'bankType',
	fieldLabel : '银行类别',
	store : bank_store,
	displayField : 'text',
	valueField : 'name',
	readOnly:true,
	typeAhead : true,
	mode : 'remote',
	triggerAction : 'all',
	selectOnFocus : true,
	itemSelector : 'div.search-item',
	tpl :  bankTpl,
	listWidth : 180,
//	emptyText : '请选择...',
	anchor : '95%',
	listWidth : 250,
	queryDelay : 0
});

var newBankType = function() {
	var bank = new Ext.form.ComboBox({
		name : 'bankType',
		fieldLabel : '银行类别',
		typeAhead : false,
		store : bank_store,
		displayField : 'text',
		valueField : 'text',
		mode : 'remote',
		triggerAction : 'all',
		selectOnFocus : true,
		hideTrigger : false,
		itemSelector : 'div.search-item',
		tpl : bankTpl,
		// emptyText : '请选择...',
		anchor : '95%',
		queryDelay : 0,
		editable :true,
		listeners : {
			"blur" : function(v) {
				this.setValue(v.getRawValue())
			}
		}
	});
return bank;
}
//////////////////////END 银行类别//////////////////////////////////////

//////////////////////员工组件下拉列表//////////////////////////////////////
//var _businesserNo ;//业务员的编号
var businesserTpl = new Ext.XTemplate('</div><tpl for=".">'
		+ '	<div class="search-item" >', '{text}', '	</div>' + '</tpl>');
var businesser_store = new Ext.data.Store({
	proxy : new Ext.data.HttpProxy({
		url : '/scmMng/proCity.do?method=getBusinesser'
	}),
	reader : new Ext.data.JsonReader({
		totalProperty : 'result.totalCount',
		root : 'result.result'
	}, [{
		name : 'name'
	},{	name : 'text'
	}])
});
function  newBusinesser(conf){
	return new Ext.form.ComboBox({
	readOnly : true,
	name:'businesser',
	fieldLabel : '主管业务员',
	store : businesser_store,
	displayField : 'text',
	valueField : 'text',
	typeAhead : true,
	mode : 'remote',
	triggerAction : 'all',
	selectOnFocus : true,
	itemSelector : 'div.search-item',
	tpl :  businesserTpl,
//	emptyText : '请选择...',
	anchor : conf.anchor,
//	pageSize : 20,
	listWidth : conf.listWidth,
	listHeight: 100,
	queryDelay : 0,
	listeners : {
		'select' : function(comb,record,index) {
			if(Ext.getCmp('busspeoNum') != undefined)
				Ext.getCmp('busspeoNum').setValue(record.get('name'));
			if(Ext.getCmp('businesserNo') != undefined)
				Ext.getCmp('businesserNo').setValue(record.get('name'));
		}
	}
});
}
var businesser = new Ext.form.ComboBox({
	 readOnly : true,
	name:'businesser',
	fieldLabel : '主管业务员',
	store : businesser_store,
	displayField : 'text',
	valueField : 'text',
	typeAhead : true,
	mode : 'remote',
	triggerAction : 'all',
	selectOnFocus : true,
	itemSelector : 'div.search-item',
	tpl :  businesserTpl,
//	emptyText : '请选择...',
	anchor : '95%',
//	pageSize : 20,
	listWidth : 260,
	listHeight: 100,
	queryDelay : 0,
	listeners : {
		'select' : function(comb,record,index) {
			if(Ext.getCmp('busspeoNum') != undefined)
				Ext.getCmp('busspeoNum').setValue(record.get('name'));
			if(Ext.getCmp('businesserNo') != undefined)
				Ext.getCmp('businesserNo').setValue(record.get('name'));
		}
	}
});
//////////////////////END 员工组件下拉列表/////////////////////////////////////


/**
 * 
 * Class ProvinceCity				add by tongliang 20080815
 * '省份'和'县市'下拉选择组件			update by tongliang 20080904
 * '省份'和'县市'的关联关系:
 * 1.改变'省份'后,'城市'置空
 * 2.'城市'下拉框中的选项与'省份'的值有对应关系
 * 
 * @param {}conf	配置对象,	配置对象conf中可以包含下列的属性:		
 * required  		省份和城市是否为必填项		
 * provinceSelected 更改'省份'后要执行的函数 		
 * citySelected   	更改'城市'后要执行的函数
 * provinceWidth 	省份选择框的宽度
 * cityWidth 		城市选择框的宽度
 */

var ProvinceCity = function(conf){ //required,provinceSelected ,citySelected ){
	Ext.apply(this,conf);
	var hid_Province = new Ext.form.Hidden( {
		name : 'provinceId'
	});
	var proCity = this;	
	
	var province = new Ext.form.ComboBox({
		readOnly : true,
		name:'province',
		allowBlank : this.required ? false : true,
		fieldLabel : this.required ? '<span id="provinceLabel">省份<font color=red>*</font></span>' : '<span id="provinceLabel">省份</span>',
		store : province_store,
		displayField : 'text',
		valueField : 'text',
		typeAhead : true,
		readOnly:true,
		mode : 'remote',
		triggerAction : 'all',
		selectOnFocus : true,
		itemSelector : 'div.search-item',
		tpl :  provinceTpl,
		listWidth : conf.provinceWidth || 180,
		width : conf.provinceWidth,
		queryDelay : 0,
		listeners : {
			'select' : function(com,rec,index) {
				hid_Province.setValue(rec.get('name'));
				if( proCity.provinceSelected ){
					proCity.provinceSelected(com,rec,index);
				}
			}
		}
	});// end province
	
	var cityStore = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : '/scmMng/proCity.do?method=getCities'
		}),
		reader : new Ext.data.JsonReader({
			totalProperty : 'result.totalCount',
			root : 'result.result'
		}, [{
			name : 'name'
		}, {
			name : 'text'
		}])
	});
	
	var hid_City = new Ext.form.Hidden( {
		name : 'cityId'
	});
	var city = new Ext.form.ComboBox({
		readOnly : true,
		name:'city',
		allowBlank :  this.required ? false : true,
		fieldLabel : this.required ? '<span id="cityLabel">城市<font color=red>*</font></span>':'<span id="cityLabel">城市</span>',
		store : cityStore,
		displayField : 'text',
		valueField : 'text',
		typeAhead : true,
		mode : 'remote',
		readOnly:true,
		triggerAction : 'all',
		selectOnFocus : true,
		itemSelector : 'div.search-item',
		tpl :  cityTpl,
		listWidth : conf.cityWidth || 180,
		width: conf.cityWidth,
		queryDelay : 0,
		listeners : {
			'select' : function(com,rec,index) {
						hid_City.setValue(rec.get('name'));
						if( proCity.citySelected ){
							proCity.citySelected(com,rec,index);
						}
			}
		}
	});// end city
	
	// 为city增加getStore方法
	Ext.apply( city,{
		getStore : function(){
	       return this.store ;
		}
	});
	
	// 修改province的setValue()方法
	Ext.apply( province,{
		setValue : function(v){
	        var text = v;
	        if(this.valueField){
	            var r = this.findRecord(this.valueField, v);
	            if(r){
	                text = r.data[this.displayField];
	            }else if(this.valueNotFoundText !== undefined){
	                text = this.valueNotFoundText;
	            }
	        }
	        this.lastSelectionText = text;
	        if(this.hiddenField){
	            this.hiddenField.value = v;
	        }
	        Ext.form.ComboBox.superclass.setValue.call(this, text);
	        this.value = v;
	        
	        // 重新加载city中的数据
			proCity.reloadCity( this.value );
		}
	});
	
	
	// 更改'省份'后，若'城市'中的内容置空
	province.on("beforeselect",
				function(com,rec) {
					cityReset = false;
					if( com.getValue() != rec.data.text ){
						city.reset();				
						cityReset = true;
					}			
				}
	);
	
	var cityReset ;
	
	
	this.isCityReset = function(){
		return cityReset;
	};
	
	this.getProvince = function(){
		return province;
	};
	this.getHidProvince=function(){
		return hid_Province;
	};
	this.getCity = function(){
		return city;
	};
	this.getHidCity=function(){
		return hid_City;
	};
	this.reloadCity = function( params ){
		params = params||'';
		var store = city.getStore();
		store.removeAll();
		if( params != '' ){
			store.baseParams.province = params;
			store.reload();
		}
	};
	
};// end ProvinceCity

